<?php

namespace app\index\controller;

use app\index\model\Type as TypeModel;
use app\index\model\Message as MessageModel;
use app\index\validate\MessageValidate;
use think\Controller;
use think\Request;

class Message extends BaseController
{
    /**
     * 案例类目
     */
    public function type()
    {
        $type = TypeModel::getByType(2);
        $this->successes(compact('type'));
    }

    /**
     * 留言
     */
    public function create(MessageModel $messageModel, MessageValidate $messageValidate)
    {
        $data = $this->request->post();
        if (!$messageValidate->batch()->check($data)) {
            $this->errorMsg($messageValidate->getError());
        }
        $res = $messageModel->allowField(true)->save($data);
        $res ? $this->successes() : $this->errorMsg('留言失败，请联系管理员');
    }
}
